<?php
date_default_timezone_set('America/Lima');

$eop=(substr(dirname($_SERVER["SCRIPT_NAME"]),-1,1) == "/") ? '' : '/';

if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") {
    defined('PROTO') || define('PROTO', 'https://');
}else{
    defined('PROTO') || define('PROTO', 'http://');
}

defined('ROOT_DIR') || define('ROOT_DIR', dirname(dirname(dirname(__FILE__))));
defined('APPLICATION_PATH') || define('APPLICATION_PATH', ROOT_DIR . '/application');
defined('COMPONENTS_ADMIN_PATH') || define('COMPONENTS_ADMIN_PATH', APPLICATION_PATH.'/components');
defined('BASE_URL') || define('BASE_URL', PROTO.$_SERVER['HTTP_HOST'].dirname($_SERVER["SCRIPT_NAME"]).$eop);
defined('TEMPLATE') || define('TEMPLATE', '');

require_once 'Zend/Loader/Autoloader.php';
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));



$loader = Zend_Loader_Autoloader::getInstance();
set_include_path('.'
. PATH_SEPARATOR . ROOT_DIR.'/library'
. PATH_SEPARATOR . APPLICATION_PATH . '/models'
. PATH_SEPARATOR . APPLICATION_PATH . '/forms'
. PATH_SEPARATOR . get_include_path()
);
$loader->setFallbackAutoloader(true);

$config = new Zend_Config_Ini(ROOT_DIR.'/application/configs/application.ini', APPLICATION_ENV);

$db = Zend_Db::factory($config->resources->multidb->auth);
//$db->getProfiler()->setEnabled(true);//para debug de queries

Zwei_Db_Table::setDefaultAdapter($db);
Zwei_Db_Table::setDefaultLogMode($config->zwei->db->table->logbook);